package iterator

import "errors"

type tLinkedListIterator struct {
	list *tLinkedList
	current *tLinkedNode
}


func newLinkedListIterator(list *tLinkedList) IIterator {
	return &tLinkedListIterator{
		list, list.head,
	}
}

func (me *tLinkedListIterator) More() bool {
	return me.current != nil
}

func (me *tLinkedListIterator) Next() (error, interface{}) {
	node := me.current
	if node == nil {
		return errors.New("no more elements"), nil
	}

	me.current = me.current.next
	return nil, node.value
}